<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>新增表单</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../component/pear/css/pear.css">
    <script src="../../js/myUtils.js"></script>
    <style>
        .layui-badge-dot{
            margin-right: 5px;
        }
    </style>
</head>

<body class="pear-container">
    <div class="nav">
        <h5 class="nav-title">目录</h5>
        <ul>
            <li><a href="#mulu-1">基本信息录入</a></li>
            <li><a href="#mulu-2">举报人信息</a></li>
            <li><a href="#mulu-3">被举报人信息</a></li>
            <li><a href="#mulu-5">线索移送</a></li>
            <li><a href="#mulu-6">信息反馈</a></li>
            <li><a href="#mulu-4">查结情况</a></li>
        </ul>
    </div>
    <div class="layui-row layui-col-space10">
        <form class="layui-form" action="" lay-filter="example" id="formView">
            <script id="formHtml" type="text/html">
                <div class="layui-card">
                    <div class="layui-card-body" style="padding-bottom: 15px;">
                        <fieldset class="table-search-fieldset">
                            <legend class="legend-style">
                                <a name="mulu-1">基本信息录入</a>
                            </legend>
                            <div id="baseInfoDIV">

                                <div class="layui-form-item">
                                    <label class="layui-form-label"><span class="layui-badge-dot"></span>受理编号</label>
                                    <div class="layui-input-inline" id='noDIV'></div>

                                    <label class="layui-form-label" style='width: auto;'><span class="layui-badge-dot"></span>一手来源单位</label>
                                    <div class="layui-input-inline">
                                        <select name="reportFrom" id="reportFrom" lay-verify="required"  lay-filter="reportFrom">
                                            {{# layui.each(d.reportFrom, function(index, item){ }}
                                                <option value={{item.value}}>{{item.label}}</option>
                                            {{# }); }}
                                        </select>
                                    </div>

                                    <div id='reportFromDIV'>
                                        <label class="layui-form-label"></span>线索来源</label>
                                        <div class="layui-input-inline">
                                            <select name="reportType" id="reportType" lay-search="">
                                                {{# layui.each(d.reportType, function(index, item){ }}
                                                    <option value={{item.value}}>{{item.label}}</option>
                                                {{# }); }}
                                            </select>
                                        </div>
                                    </div>

                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label" style="width: auto;">来电来信线索编号</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="mailNo" autocomplete="off" placeholder="请输入致信来电编号"
                                            class="layui-input">
                                    </div>

                                    <label class="layui-form-label" style='width: auto;'>是否还要来信反映</label>
                                    <div class="layui-input-inline">
                                        <select name="moreLetter" id="moreLetter">
                                            <option value="0">否</option>
                                            <option value="1">是</option>
                                        </select>
                                    </div>
                                </div>
                            </div>

                            <label class="layui-form-label">涉及区域</label>
                            <div class="area-button" style="margin: 20px 30px;">
                                <button data-type="areaAdd" type="button" class="layui-btn layui-btn-sm area-active">
                                    <i class="layui-icon">&#xe654;</i>
                                </button>
                                <button data-type="areaDelete" type="button"
                                    class="layui-btn layui-btn-danger layui-btn-sm area-active">
                                    <i class="layui-icon">&#xe67e;</i>
                                </button>
                            </div>

                            <div id="addressDIV">
                                <!-- 动态插入地区选择器 -->
                            </div>

                            <label class="layui-form-label"><span class="layui-badge-dot"></span>涉案类别</label>
                            <div class="layui-input-inline">
                                <select name="reportCaseType" id="reportCaseType" lay-verify="required"  lay-filter="reportCaseType">
                                    {{# layui.each(d.reportCaseType, function(index, item){ }}
                                        <option value={{item.value}}>{{item.label}}</option>
                                    {{# }); }}
                                </select>
                            </div>
                        </fieldset>
                    </div>
                </div>

                <div class="layui-card">
                    <div class="layui-card-body" style="padding-bottom: 15px;">
                        <fieldset class="table-search-fieldset">
                            <legend class="legend-style">
                                <a name="mulu-2">举报人信息</a>
                            </legend>
                            <div id="reportPersonDIV">
                                <div class="layui-form-item">
                                    <label class="layui-form-label"><span class="layui-badge-dot"></span>姓名</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="name" lay-verify="required" lay-reqtext="举报人姓名是必填项，不能为空"
                                            placeholder="请输入姓名" autocomplete="off" class="layui-input">
                                    </div>

                                    <label class="layui-form-label">身份证号</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="cardId" lay-verify="identity" lay-reqtext="身份证号是必填项，不能为空"
                                            placeholder="请输入身份证号" autocomplete="off" class="layui-input">
                                    </div>

                                    <label class="layui-form-label">联系方式</label>
                                    <div class="layui-input-inline">
                                        <input type="tel" name="phone" lay-verify="phone" autocomplete="off"
                                            class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label">住所地</label>
                                    <div class="layui-input-inline" style="width: 510px;">
                                        <input type="text" name="location" placeholder="请输入住所地" autocomplete="off"
                                            class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item layui-form-text">
                                    <label class="layui-form-label layui-input-inline" style="padding-left: 56px;">备注</label>
                                    <div class="layui-input-block">
                                        <textarea placeholder="如含有多个举报人或其它情况可在此说明" class="layui-textarea" name='memo'
                                            style="width: 1000px;"></textarea>
                                    </div>
                                </div>
                            </div>
                        </fieldset>
                    </div>
                </div>

                <div class="layui-card">
                    <div class="layui-card-body" style="padding-bottom: 15px;">
                        <fieldset class="table-search-fieldset">
                            <legend class="legend-style">
                                <a name="mulu-3">被举报人信息</a>
                            </legend>
                            <div class="black-person-button">
                                <button data-type="tabAdd" type="button" class="layui-btn layui-btn-sm black-person-active">
                                    <i class="layui-icon">&#xe654;</i>
                                </button>
                                <button data-type="tabDelete" type="button"
                                    class="layui-btn layui-btn-danger layui-btn-sm black-person-active">
                                    <i class="layui-icon">&#xe67e;</i>
                                </button>
                            </div>

                            <div id="blackInfoDIV">
                                <div class="layui-tab" lay-filter="black-person" style="margin: 15px 30px;">
                                    <ul class="layui-tab-title">
                                        <li class="layui-this" lay-id="black-1">被举报人1</li>
                                    </ul>
                                    <div class="layui-tab-content">
                                        <div class="layui-tab-item layui-show">
                                            <div class="layui-form-item" id='black-1'>

                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label" style="margin-right: 9px;">是否重复</label>
                                <div class="layui-input-inline">
                                    <select name="isRepeat" id="isRepeat" lay-filter="isRepeat">
                                        {{# layui.each(d.isRepeat, function(index, item){ }}
                                            <option value={{item.value}}>{{item.label}}</option>
                                        {{# }); }}
                                    </select>
                                </div>

                                <div id="repeatReportNoDiv">
                                    <label class="layui-form-label" style="margin-right: 9px;">重复编号</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="repeatReportNo" id="repeatReportNo" autocomplete="off"
                                            placeholder="请输入重复的编号" class="layui-input">
                                    </div>
                                </div>
                            </div>

                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label layui-input-inline" style="padding-left: 48px;"><span class="layui-badge-dot"></span>主要问题</label>
                                <div class="layui-input-block">
                                    <textarea placeholder="请输入内容" lay-verify="required" lay-reqtext="主要问题不能为空"
                                        class="layui-textarea" name='question' style="width: 1000px;"></textarea>
                                </div>
                            </div>
                        </fieldset>
                    </div>
                </div>

                <div class="layui-card">
                    <div class="layui-card-body" style="padding-bottom: 15px;">
                        <fieldset class="table-search-fieldset">
                            <legend class="legend-style">
                                <a name="mulu-5">线索移送</a>
                            </legend>
                            <div class="layui-form-item">
                                <label class="layui-form-label">是否移送</label>
                                <div class="layui-input-inline">
                                    <select name="isSend" id="isSend" lay-filter="isSend">
                                        <option value="0">否</option>
                                        <option value="1">是</option>
                                    </select>
                                </div>
                            </div>
                            
                            <div id="sendDiv">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">移交时间</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="sendTime" id="sendTime" lay-verify="date"
                                            placeholder="例如:2021-01-01" autocomplete="off" class="layui-input">
                                    </div>
                                    
                                    <label class="layui-form-label">移送编号</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="sendToId" placeholder="请输入移送编号" autocomplete="off" class="layui-input">
                                    </div>

                                    <label class="layui-form-label">移送单位</label>
                                    <div class="layui-input-inline">
                                        <select name="sendDepartment" id="sendDepartment" lay-filter="sendDepartment">
                                            {{# layui.each(d.sendDepartment, function(index, item){ }}
                                                <option value={{item.value}}>{{item.label}}</option>
                                            {{# }); }}
                                        </select>
                                    </div>


                                    <div id="sendDepartmentMemoDIV">
                                        <label class="layui-form-label">单位名称</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="sendDepartmentMemo" id="sendDepartmentMemo"
                                                autocomplete="off" placeholder="请输入具体的单位名称" class="layui-input">
                                        </div>
                                    </div>

                                    <label class="layui-form-label">反馈时限</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="feedbackTimeLimit" lay-verify="intCheck" autocomplete="off"
                                            placeholder="请输入反馈时限，例如：10" class="layui-input">
                                    </div>

                                    <label class="layui-form-label">查结时限</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="doneTimeLimit" lay-verify="intCheck" autocomplete="off"
                                            placeholder="请输入查结时限，例如：30" class="layui-input">
                                    </div>
                                </div>
                            </div>
                        </fieldset>
                    </div>
                </div>

                <div class="layui-card">
                    <div class="layui-card-body" style="padding-bottom: 15px;">
                        <fieldset class="table-search-fieldset">
                            <legend class="legend-style">
                                <a name="mulu-6">信息反馈</a>
                            </legend>
                            <div class="layui-form-item">
                                <label class="layui-form-label" style="color: orangered;">线索状态</label>
                                <div class="layui-input-inline">
                                    <select name="reportState" id="reportState" lay-filter="reportState">
                                        {{# layui.each(d.reportState, function(index, item){ }}
                                            <option value={{item.value}}>{{item.label}}</option>
                                        {{# }); }}
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">核查进展</label>
                                <div class="layui-input-inline">
                                    <select name="progress" id="progress" lay-filter="progress">
                                        {{# layui.each(d.progress, function(index, item){ }}
                                            <option value={{item.value}}>{{item.label}}</option>
                                        {{# }); }}
                                    </select>
                                </div>

                                <label class="layui-form-label">反馈时间</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="feedbackTime" id="feedbackTime" lay-verify="date"
                                        placeholder="例如:2021-01-01" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div id="feedbackInfoDIV">
                                    <label class="layui-form-label">核查等级</label>
                                    <div class="layui-input-inline">
                                        <select name="level" id="level" lay-search="">
                                            {{# layui.each(d.level, function(index, item){ }}
                                                <option value={{item.value}}>{{item.label}}</option>
                                            {{# }); }}
                                        </select>
                                    </div>

                                    <label class="layui-form-label">核查结论</label>
                                    <div class="layui-inline">
                                        <div class="layui-input-inline">
                                            <select name="conclusion" id="conclusion" lay-search="">
                                                {{# layui.each(d.conclusion, function(index, item){ }}
                                                    <option value={{item.value}}>{{item.label}}</option>
                                                {{# }); }}
                                            </select>
                                        </div>

                                        <label class="layui-form-label">四种形态</label>
                                        <div class="layui-input-inline">
                                            <select name="fourShapes" id="fourShapes" lay-search="">
                                                {{# layui.each(d.fourShapes, function(index, item){ }}
                                                    <option value={{item.value}}>{{item.label}}</option>
                                                {{# }); }}
                                            </select>
                                        </div>

                                        <label class="layui-form-label">处理结果</label>
                                        <div class="layui-input-inline">
                                            <select name="processResult" id="processResult" lay-search="">
                                                {{# layui.each(d.processResult, function(index, item){ }}
                                                    <option value={{item.value}}>{{item.label}}</option>
                                                {{# }); }}
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label layui-input-inline" style="padding-left: 66px;">备注</label>
                                <div class="layui-input-block">
                                    <textarea placeholder="请输入内容" class="layui-textarea" name='feedbackMemo'
                                        style="width: 1000px;"></textarea>
                                </div>
                            </div>
                        </fieldset>
                    </div>
                </div>

                <div class="layui-card">
                    <div class="layui-card-body" style="padding-bottom: 15px;">
                        <fieldset class="table-search-fieldset">
                            <legend class="legend-style">
                                <a name="mulu-4">查结情况</a>
                            </legend>
                            <div id="toComplete">
                                <div class="layui-form-item">
                                    <label class="layui-form-label" style="width: auto;">是否为顽瘴痼疾</label>
                                    <div class="layui-input-inline">
                                        <select name="isIssueType" id="isIssueType" lay-filter="isIssueType">
                                            <option value="0">否</option>
                                            <option value="1">是</option>
                                        </select>
                                    </div>

                                    <div id="issueTypeDIV">
                                        <label class="layui-form-label" style="width: auto;">顽瘴痼疾类别</label>
                                        <div class="layui-input-inline" id="issueType">

                                        </div>
                                    </div>

                                    <label class="layui-form-label">涉及单位</label>
                                    <div class="layui-input-inline" id="involvedUnit">

                                    </div>

                                    <label class="layui-form-label" style="width: auto;">是否主动说明情况</label>
                                    <div class="layui-input-inline">
                                        <select name="isVolunteered" id="isVolunteered">
                                            <option value="0">否</option>
                                            <option value="1">是</option>
                                        </select>
                                    </div>

                                    <label class="layui-form-label" style="width: auto;">是否属于扫黑除恶</label>
                                    <div class="layui-input-inline">
                                        <select name="isSweepBlack" id="isSweepBlack">
                                            <option value="0">否</option>
                                            <option value="1">是</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="layui-form-item layui-form-text">
                                    <label class="layui-form-label layui-input-inline"
                                        style="padding-left: 61px;">备注</label>
                                    <div class="layui-input-block">
                                        <textarea placeholder="请输入内容" class="layui-textarea" name='completeDataMemo'
                                            style="width: 1000px;"></textarea>
                                    </div>
                                </div>
                            </div>
                        </fieldset>
                    </div>
                </div>

                <div style="text-align: center; margin: 25px 0 70px 0;">
                    <button type="button" class="layui-btn layui-btn-lg layui-btn-radius" lay-submit=""
                        lay-filter="tmpSaveInfo">暂存线索
                    </button>
                    <button type="button" class="layui-btn layui-btn-lg layui-btn-radius layui-btn-normal" lay-submit=""
                        lay-filter="addInfo">添加线索
                    </button>
                </div>
            </script>
        </form>
    </div>
    <!-- 提示今日受理编号模板 -->
    <script id="noHtml" type="text/html">
        <input type="text" name="no" lay-verify="noCheck" lay-reqtext="请输入正确的受理编号！" value="{{d}}" autocomplete="off" placeholder="请输入受理编号" class="layui-input">
    </script>

    <!-- 动态增加Address模板 -->
    <script id="pcaHtml" type="text/html">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
            <select name="province-{{d}}" lay-filter="province-{{d}}" id="province-{{d}}">
                <option></option>
            </select>
        </div>
        <div class="layui-input-inline">
            <select name="city-{{d}}" lay-filter="city-{{d}}" id="city-{{d}}">
                <option></option>
            </select>
        </div>
        <div class="layui-input-inline">
            <select name="area-{{d}}" lay-filter="area-{{d}}" id="area-{{d}}">
                <option></option>
            </select>
        </div>
    </script>
    <!-- 动态增加被举报人模板 -->
    <script id="blackHtml" type="text/html">
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="layui-badge-dot"></span>姓名</label>
            <div class="layui-input-inline">
                <input type="text" name="blackName-{{d}}" lay-verify="required"
                    lay-reqtext="被举报人姓名是必填项，不能为空" placeholder="请输入姓名" autocomplete="off"
                    class="layui-input">
            </div>

            <label class="layui-form-label">身份证号</label>
            <div class="layui-input-inline">
                <input type="text" name="blackCardId-{{d}}" lay-verify="identity" lay-reqtext="请输入正确格式的身份证号"
                placeholder="有则输入身份证信息" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: auto;"><span class="layui-badge-dot"></span>身份及涉及内容</label>
            <div class="layui-input-inline">
                <input type="text" id="blackCascader-{{d}}" class="layui-input cascader-input" style="width: 400px;" readonly="readonly">
            </div>
        </div>
    </script>
    <script src="../../js/xm-select.js"></script>
    <script src="../../component/layui/layui.js"></script>
    <script src="../../component/pear/pear.js"></script>
    <script>
        var options = layui.data('options').data
        layui.use(['form', 'layedit', 'laydate', 'laytpl', 'util', 'pca', 'Api', 'request', 'cascader', 'loading'], function () {
            var $ = layui.jquery,
                element = layui.element,
                form = layui.form,
                layer = layui.layer,
                layedit = layui.layedit,
                laytpl = layui.laytpl,
                laydate = layui.laydate,
                Api = layui.Api,
                util = layui.util,
                pca = layui.pca,
                request = layui.request,
                loading = layui.loading,
                cascader = layui.cascader;

            /** 初始化全局变量和函数 **/
            var blackSelected = {}
            var tabBlackID = []
            var tabIDIndex = 1
            var pcaIDList = []
            var pcaIDIdex = 1
            var issueType, involvedUnit
            loading.Load(1, '加载中');
            initForm()

            function initForm() {
                var getFormTpl = formHtml.innerHTML,
                    formView = document.getElementById('formView');
                // console.log("initForm options: ", options)
                laytpl(getFormTpl).render(options, function (html) {
                    formView.innerHTML = html;
                    /** 提示案件编号 **/
                    initNo()
                    /** 初始化日期选择器 **/
                    initLaydate()
                    /** 默认选择 **/
                    initSelected()
                    /** 初始化地址选择器 **/
                    loadPcaTpl(pcaIDIdex)
                    /** 初始化xm-select多选框 **/
                    initXmselect()
                    /** 初始化第一个被举报人 **/
                    loadBlackTpl(tabIDIndex, 'black-1')
                    /** 初始化需要隐藏的DIV **/
                    initHide()
                    /** 初始化监听地址和被举报人的新增和删除 **/
                    listenABChange()
                    /** 初始化监听选择 **/
                    listenSelect()

                    loading.loadRemove(1000);
                });
            }

            function initSelected() {
                $("#isRepeat").find("option[value=0]").prop("selected", true);
                $("#progress").find("option[value=0]").prop("selected", true);
                $("#reportState").find("option[value=-1]").prop("selected", true);
            }

            function listenABChange() {
                var active = {
                    tabAdd: function () {
                        //新增一个Tab项
                        tabIDIndex = tabIDIndex + 1
                        var tabID = 'black-' + tabIDIndex
                        tabBlackID.push(tabID)

                        // 传入Number和tabID渲染模板
                        loadBlackTpl(tabIDIndex, tabID)
                    },
                    tabDelete: function (othis) {
                        //删除指定Tab项
                        if (tabIDIndex > 1) {
                            layer.confirm('确定删除？', {
                                btn: ['确定', '取消']
                            }, function (index, layero) {
                                layer.close(index)
                                element.tabDelete('black-person', tabBlackID.pop());
                                tabIDIndex = tabIDIndex - 1
                            }, function (index) {
                                // 用户点击取消
                            });
                            return false;
                        }
                    },
                    areaAdd: function () {
                        pcaIDIdex = pcaIDIdex + 1
                        // console.log("areaAdd: ", pcaIDIdex)
                        var pcaID = 'pca-' + pcaIDIdex
                        pcaIDList.push(pcaID)
                        loadPcaTpl(pcaIDIdex)
                    },
                    areaDelete: function (othis) {
                        if (pcaIDList.length != 0) {
                            layer.confirm('确定删除？', {
                                btn: ['确定', '取消']
                            }, function (index, layero) {
                                layer.close(index)
                                $("#" + pcaIDList.pop()).remove();
                                pcaIDIdex = pcaIDIdex - 1
                            }, function (index) {
                                // 用户点击取消
                            });
                            return false;
                        }
                    }

                };
                $('.black-person-active').on('click', function () {
                    var othis = $(this), type = othis.data('type');
                    active[type] ? active[type].call(this, othis) : '';
                });
                $('.area-active').on('click', function () {
                    var othis = $(this), type = othis.data('type');
                    active[type] ? active[type].call(this, othis) : '';
                });
            }

            function loadPcaTpl() {
                var body = document.getElementById("addressDIV");
                var div = document.createElement("div");
                var divID = "pca-" + pcaIDIdex;
                div.id = divID
                div.setAttribute('class', 'layui-form-item')
                div.setAttribute('style', 'margin-top: 15px;')
                body.appendChild(div);

                var getTpl = pcaHtml.innerHTML,
                    view = document.getElementById(divID);
                laytpl(getTpl).render(pcaIDIdex, function (html) {
                    view.innerHTML = html;
                });
                pca.init('select[name=province-' + pcaIDIdex + ']', 'select[name=city-' + pcaIDIdex + ']', 'select[name=area-' + pcaIDIdex + ']', '福建', '厦门', '全部');
            }

            function loadBlackTpl(numberID, tabID) {
                if (numberID > 1) {
                    var html = '<div class="layui-form-item" id=' + tabID + '> </div>'
                    element.tabAdd('black-person', {
                        title: '被举报人' + numberID,
                        content: html,
                        id: tabID
                    })
                }

                var getTpl = blackHtml.innerHTML,
                    view = document.getElementById(tabID);
                laytpl(getTpl).render(numberID, function (html) {
                    view.innerHTML = html;
                });

                getBlackSelect(numberID)
                form.render('select')
            }

            function initHide() {
                $('#repeatReportNoDiv').hide()
                $('#sendDiv').hide()
                $('#sendDepartmentMemoDIV').hide()
                $('#feedbackInfoDIV').hide()
                $('#issueTypeDIV').hide()
                $('#reportFromDIV').hide()
            }

            function initNo() {
                var today = myUtils.getToday()
                today = today.replaceAll('-', '')
                today = today.substring(2)

                var noFormat = '驻2线' + today + '第N号'
                var getTpl = noHtml.innerHTML,
                    view = document.getElementById('noDIV');

                laytpl(getTpl).render(noFormat, function (html) {
                    view.innerHTML = html;
                });
            }

            //自定义验证规则
            form.verify({
                noCheck: function (value) {
                    // console.log("noCheck value: ", value)
                    if (value.indexOf("N号") != -1 || value == '') {
                        return "请输入正确的受理编号！"
                    }
                },
                intCheck: [
                    /(^$)|^[1-9]\d*$/
                    , '天数必须大于0哦'
                ],
                select: function (value) {
                    if (value == '-1' || value == '') {
                        return "线索来源不能为空！"
                    }
                }
            });

            function initLaydate() {
                //日期
                laydate.render({
                    elem: '#sendTime',
                    format: 'yyyy-MM-dd',
                    trigger: 'click'
                });
                laydate.render({
                    elem: '#feedbackTime',
                    format: 'yyyy-MM-dd',
                    trigger: 'click'
                });
            }

            function initXmselect() {
                // xm-select
                issueType = xmSelect.render({
                    el: '#issueType',
                    prop: {
                        name: 'label',
                        value: 'value',
                    },
                    data: myUtils.deleteUnselected(options.issueType),
                    direction: 'up',
                    height: 'auto',
                    autoRow: true,
                })
                involvedUnit = xmSelect.render({
                    el: '#involvedUnit',
                    prop: {
                        name: 'label',
                        value: 'value',
                    },
                    data: myUtils.deleteUnselected(options.involvedUnit),
                    on: function (data) {
                        // arr: 当前多选已选中的数据
                        // var arr = data.arr;
                    },
                    direction: 'up',
                    height: 'auto',
                    autoRow: true,
                })
            }

            function listenSelect() {
                $("#repeatReportNo").blur(function (event) {
                    // $("input").css("background-color", "#D6D6FF");
                    // console.log("失去聚焦")
                    let repeatNo = $("#repeatReportNo").val()
                    repeatNo = $.trim(repeatNo)
                    if(repeatNo == '') {
                        return
                    }
                    let params = {
                        no: repeatNo
                    }
                    var success = function (res) {
                        if (res.errno == 0) {
                            // console.log("已有案件的信息：", res.data)
                        } else {
                            layer.alert('该重复编号不存在', { icon: 2 });
                        }
                    }
                    request.get(Api.getByNo, params, success)
                });

                form.on('select(isRepeat)', function (data) {
                    // console.log("isRepeat: ", data.value)
                    var input = document.getElementById("repeatReportNo");
                    if (data.value == "0") {
                        $('#repeatReportNoDiv').hide()
                    } else {
                        $('#repeatReportNoDiv').show()
                    }
                });

                form.on('select(isSend)', function (data) {
                    var processValue = $("#progress").find("option:selected").val()
                    // console.log("processValue: ", processValue)
                    if (data.value == "1") {
                        $('#sendDiv').show()
                        if (processValue == '0') {
                            $("#progress").find("option[value=1]").prop("selected", true);
                            $("#reportState").find("option[value=1]").prop("selected", true);
                            $('#feedbackInfoDIV').show()
                        }
                    } else {
                        $('#sendDiv').hide()
                        if (processValue != '0') {
                            $("#progress").find("option[value=0]").prop("selected", true);
                            $("#reportState").find("option[value=0]").prop("selected", true);
                            $('#feedbackInfoDIV').hide()
                        }
                    }
                    form.render('select')
                });

                form.on('select(reportState)', function (data) {
                    // console.log("移送状态: ", data.value)
                    if (data.value == "-1" || data.value == '0') { // 暂存 || 未移送
                        $("#isSend").find("option[value=0]").prop("selected", true);
                        $("#progress").find("option[value=0]").prop("selected", true);
                        $('#sendDiv').hide()
                        $('#feedbackInfoDIV').hide()
                    } else {
                        $("#isSend").find("option[value=1]").prop("selected", true);
                        $("#progress").find("option[value=1]").prop("selected", true);
                        $('#sendDiv').show()
                        $('#feedbackInfoDIV').show()
                    }
                    form.render('select')
                });

                form.on('select(progress)', function (data) {
                    if (data.value == "1") { // 核查中
                        $('#feedbackInfoDIV').show()
                        $('#sendDiv').show()
                        $("#isSend").find("option[value=1]").prop("selected", true);
                        $("#reportState").find("option[value=1]").prop("selected", true);
                    } else {
                        if(data.value == "2"){ // 查结
                            $('#feedbackInfoDIV').show()
                            $('#sendDiv').show()
                            $("#isSend").find("option[value=1]").prop("selected", true);
                            $("#reportState").find("option[value=3]").prop("selected", true);
                        }else{
                            $('#feedbackInfoDIV').hide()
                            $('#sendDiv').hide()
                            $("#isSend").find("option[value=0]").prop("selected", true);
                            $("#reportState").find("option[value=0]").prop("selected", true);
                        }
                    }
                    form.render('select')
                });

                form.on('select(sendDepartment)', function (data) {
                    // console.log("移送单位: ", data.value)
                    var input = document.getElementById("sendDepartmentMemo");
                    if (data.value == "0") { // 其它外单位
                        $('#sendDepartmentMemoDIV').show()
                    } else {
                        $('#sendDepartmentMemoDIV').hide()
                    }
                });

                form.on('select(isIssueType)', function (data) {
                    if (data.value == "0") { // 否
                        $('#issueTypeDIV').hide()
                    } else {
                        $('#issueTypeDIV').show()
                    }
                });

                form.on('select(reportFrom)', function(data){
                    // console.log('reportFrom val', data.value)
                    if (data.value == "8"){
                        // 选到 【8 指导组】 才有 线索来源
                        $('#reportFromDIV').show()
                    }else{
                        $('#reportFromDIV').hide()
                    }
                    form.render('select')
                });
            }

            //监听提交
            form.on('submit(addInfo)', function (data) {
                console.log('addInfo params:', JSON.stringify(data.field))
                var params = getTotalParams(data.field)
                if(params['reportState'] == '-1'){
                    layer.alert('当前【线索状态】为【暂存】，不能直接添加线索', { icon: 2 });
                    return false;
                }
                if(params['progress'] == '2'){
                    // 如果进展为已查结，则状态为已完成
                    params['reportState'] = '3'
                }
                layer.confirm('您确定新增吗？', {
                    btn: ['确定', '取消']
                }, function (index, layero) {
                    var success = function (res) {
                        if (res.errno == 0) {
                            // console.log("addExcel res: ", res)
                            layer.alert('新增成功!', { icon: 1 }, function () {
                                location.reload();
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index); //关闭当前页
                            });
                            // layer.msg('新增成功!', {
                            //     time: 20000, //20s后自动关闭
                            //     btn: ['知道了']
                            // }, function () {
                            //     // var index = parent.layer.getFrameIndex(window.name);
                            //     // parent.layer.close(index); //关闭当前页

                            // });
                        } else {
                            layer.alert(res.errmsg, { icon: 2 });
                        }
                    }
                    request.post(Api.report, params, success)
                }, function (index) {
                    // 用户点击取消 
                });

                return false;
            });

            //监听暂存
            form.on('submit(tmpSaveInfo)', function (data) {
                // console.log('tmpSaveInfo params:', JSON.stringify(data.field))
                var params = getTotalParams(data.field)
                params['reportState'] = '-1' // 强制状态为暂存
                // console.log("reportState", params)
                layer.confirm('您确定暂存吗？', {
                    btn: ['确定', '取消']
                }, function (index, layero) {
                    var success = function (res) {
                        if (res.errno == 0) {
                            // console.log("addExcel res: ", res)
                            layer.alert('暂存成功!', { icon: 1 }, function () {
                                location.reload();
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index); //关闭当前页
                            });
                        } else {
                            layer.alert(res.errmsg, { icon: 2 });
                        }
                    }
                    request.post(Api.report, params, success)
                }, function (index) {
                    // 用户点击取消 
                });

                return false;
            });

            function getBlackSelect(numberID) {
                /** 获得下拉选择项 **/
                cascader({
                    elem: "#blackCascader-" + numberID,
                    data: myUtils.getCascaderData(options),
                    triggerType: "click",
                    success: function (valData, labelData) {
                        if (valData.length < 5) {
                            let addLen = 5 - valData.length
                            for (let i = 0; i < addLen; i++) {
                                valData.push(-1)
                            }
                        }
                        blackSelected["blackCascader-" + numberID] = valData
                        // console.log("valData: ", valData);
                    }
                });
            }

            function getTotalParams(params) {
                // 去除首尾空格
                params['no'] = $.trim(params['no'])
                // 封装地址和被举报人信息
                params = myUtils.pieceAddress(params, pcaIDIdex)
                params = myUtils.pieceBlackInfo(params, blackSelected)
                params = myUtils.pieceReporter(params)
                // 获取xm-select组件的值（复选）
                params['issueType'] = myUtils.cleanXmSelect(issueType.getValue())
                params['involvedUnit'] = myUtils.cleanXmSelect(involvedUnit.getValue())
                // 获取录入人姓名
                let userInfoData = layui.data('userInfo').item
                params['enterer'] = userInfoData.name
                params = myUtils.setNull(params)
                // console.log("getTotalParams: ", params)
                return params
            }
        });

    </script>
</body>

</html>